package SwordForOffer.Problem15;

public class MyFindKthToTail {
    public MyListNode findKthToTail(MyListNode head, int k) {
        if(head == null || k == 0){
            return null;
        }
        MyListNode outputNode = head;
        MyListNode currentNode = head;
        for(int i = 1; i < k ; i++){
            if(currentNode.nextNode != null){
                currentNode = currentNode.nextNode;
            }else{
                return null;
            }
        }
        while(currentNode.nextNode != null){
            currentNode = currentNode.nextNode;
            outputNode = outputNode.nextNode;
        }

        return outputNode;

    }
}

class MyListNode {
    int data;
    MyListNode nextNode;
}
